﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CrystalDecisions.Enterprise.Desktop;

namespace BO.Management
{
    /// <summary>
    /// Class to manage content folders
    /// </summary>
    public class ContentFolderProvider:BaseInfoObjectProvider<Folder>
    {

        /// <summary>
        /// Default constructor required the LogonProvider used to connect to BO Cms
        /// </summary>
        /// <param name="logonProvider"></param>
        public ContentFolderProvider(LogonProvider logonProvider)
            : base(logonProvider)
        {
           
        }

        public override ObjectKind Kind
        {
            get
            {
                return ObjectKind.Folder;
            }
        }

        public static BOPathInformation GetFullPath(Folder folder)
        {
            BOPathInformation info = new BOPathInformation();
            info.Id = folder.ID;

            Int32 nbFolders = (Int32)folder.Properties["SI_PATH"].Properties["SI_NUM_FOLDERS"].Value;
            //WriteVerbose(String.Format("Path is composed of {0} folders", nbFolders));

            if (nbFolders > 0)
            {
                for (Int32 i = nbFolders; i > 0; i--)
                {
                    String tempPath = (String)folder.Properties["SI_PATH"].Properties["SI_FOLDER_NAME" + i.ToString()].Value;
                    //WriteVerbose(String.Format("Read path {0} with value {1}", tempPath, i));

                    info.FullPath += tempPath + @"\";
                }
            }

            info.Name = folder.Title;
            info.FullPath += folder.Title;
            info.LastUpdated = folder.GetUpdateTimeStamp();

            return info;
        }


    }
}
